﻿using System.IO;
using RazorEngine;

namespace Quintsys.Core.Services
{
    public interface IEmailTemplateResolver
    {
        /// <summary>
        /// Gets the email body.
        /// </summary>
        /// <param name="templatePath">The template path.</param>
        /// <param name="model">The model.</param>
        /// <returns></returns>
        string GetEmailBody(string templatePath, dynamic model);
    }

    public class EmailTemplateResolver : IEmailTemplateResolver
    {
        /// <summary>
        /// Gets the email body.
        /// </summary>
        /// <param name="templatePath">The template path.</param>
        /// <param name="model">The model.</param>
        /// <returns></returns>
        public string GetEmailBody(string templatePath, dynamic model)
        {
            var template = File.ReadAllText(templatePath);
            var body = Razor.Parse(template, model);
            return body;
        }
    }
}